﻿<%@ Page Language="C#" MasterPageFile="~/MasterPages/MasterPage.master" AutoEventWireup="true" CodeFile="Suppliers.aspx.cs" Inherits="Companies_Suppliers" Title="Доставчици" %>

<%@ Register assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" namespace="System.Web.UI.WebControls" tagprefix="asp" %>

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <br />
    <br />
    <br />
    СПИСЪК НА ДОСТАВЧИЦИТЕ:<br />
    <asp:GridView ID="gvSuppliers" runat="server" AutoGenerateColumns="False" 
        DataKeyNames="SupplierID" DataSourceID="sdsSuppliers" 
        onselectedindexchanged="gvSuppliers_SelectedIndexChanged" 
    BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" 
    CellPadding="4" ForeColor="Black" GridLines="Vertical">
        <FooterStyle BackColor="#CCCC99" />
        <RowStyle BackColor="#F7F7DE" />
             <Columns>
                <asp:CommandField SelectText="Избери" ShowSelectButton="True" />
                <asp:BoundField DataField="Name" HeaderText="Име" SortExpression="Name" />
                <asp:BoundField DataField="IDNUM" HeaderText="Идент. №" 
                    SortExpression="IDNUM" />
                <asp:BoundField DataField="VATNO" HeaderText="Идент. № по ЗДДС/VATNO" 
                    SortExpression="VATNO" />
                <asp:BoundField DataField="MRP" HeaderText="МОЛ" 
                    SortExpression="MRP" />
                <asp:BoundField DataField="Phone" HeaderText="Телефон" SortExpression="Phone" />
                <asp:BoundField DataField="Fax" HeaderText="Факс" SortExpression="Fax" />
                <asp:BoundField DataField="NameBG" HeaderText="Държава" 
                    SortExpression="NameBG" />
                <asp:TemplateField HeaderText="Продукти">
                    <ItemTemplate>
                      <a href='SuppProducts.aspx?SupplierID=<%# Eval("SupplierID") %>'>Продукти</a> 
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
        <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
        <AlternatingRowStyle BackColor="White" />
    </asp:GridView>
    <asp:SqlDataSource ID="sdsSuppliers" runat="server" 
        
        SelectCommand="SELECT Suppliers.SupplierID, Suppliers.IDNUM, Suppliers.Name, Suppliers.VATNO, Suppliers.MRP, Suppliers.Phone, Suppliers.Fax, Countries.NameBG FROM Suppliers INNER JOIN Countries ON Suppliers.CountryID = Countries.CountryID" 
        ConnectionString="<%$ ConnectionStrings:KonturConnectionString %>"></asp:SqlDataSource>
    <br />
    <asp:Button ID="btnNewSuppliers" runat="server" Text="Създай нов даставчик" 
        onclick="btnNewSuppliers_Click" />
    <br />
    <br />
    <asp:DetailsView ID="dvSuppliers" runat="server" AllowPaging="True" 
            AutoGenerateRows="False" DataKeyNames="SupplierID" 
            DataSourceID="sdsSuppliersDetails" Height="50px" Width="385px" 
            onitemdeleted="dvSuppliers_ItemDeleted" 
            oniteminserted="dvSuppliers_ItemInserted" 
            onitemupdated="dvSuppliers_ItemUpdated" 
            BackColor="White" 
            BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4" 
            ForeColor="Black" GridLines="Vertical">
            <FooterStyle BackColor="#CCCC99" />
            <RowStyle BackColor="#F7F7DE" />
            <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
            <Fields>
                <asp:BoundField DataField="Name" HeaderText="Име" SortExpression="Name" />
                <asp:BoundField DataField="AddressInvoice" HeaderText="Адрес за фактури" 
                    SortExpression="AddressInvoice" />
                <asp:BoundField DataField="AddressCorrespondence" 
                    HeaderText="Адрес за кореспонденция" SortExpression="AddressCorrespondence" />
                <asp:BoundField DataField="IDNUM" HeaderText="Идент. №" 
                    SortExpression="IDNUM" />
                <asp:BoundField DataField="VATNO" HeaderText="Идентификационен № по ЗДДС/VAT" 
                    SortExpression="VATNO" />
                <asp:BoundField DataField="MRP" HeaderText="МОЛ:" SortExpression="MRP" />
                <asp:BoundField DataField="Phone" HeaderText="Телефон" SortExpression="Phone" />
                <asp:BoundField DataField="Fax" HeaderText="Факс" SortExpression="Fax" />
                <asp:BoundField DataField="Website" HeaderText="Уебсайт" SortExpression="Website" />
                <asp:BoundField DataField="Bank" HeaderText="Банка" SortExpression="Bank" />
                <asp:BoundField DataField="BankAddress" HeaderText="Адрес на банката" 
                    SortExpression="BankAddress" />
                <asp:BoundField DataField="AccountNo" HeaderText="Сметка №" SortExpression="AccountNo" />
                <asp:BoundField DataField="IBAN" HeaderText="IBAN" SortExpression="IBAN" />
                <asp:BoundField DataField="BIC" HeaderText="BIC" SortExpression="BIC" />
                <asp:BoundField DataField="BankGiro" HeaderText="BankGiro" SortExpression="BankGiro" />
                <asp:BoundField DataField="PostGiro" HeaderText="PostGiro" SortExpression="PostGiro" />
                <asp:TemplateField HeaderText="Държава" SortExpression="NameBG">
                    <EditItemTemplate>
                        <asp:DropDownList ID="ddlCountries" runat="server" DataSourceID="sdsCountries" DataTextField="NameBG" DataValueField="CountryID">
                        </asp:DropDownList>
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        <asp:DropDownList ID="ddlCountriesIns" runat="server" DataSourceID="sdsCountries" DataTextField="NameBG" DataValueField="CountryID">
                        </asp:DropDownList>
                    </InsertItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("NameBG") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" 
                    ShowInsertButton="True" CancelText="Прекъсни" DeleteText="Изтриване" 
                    EditText="Редактиране" InsertText="Вмъкване" NewText="Нов" SelectText="Избери" 
                    UpdateText="Обнови" />
            </Fields>
            <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
            <HeaderTemplate>
                Детайли
                <br />
            </HeaderTemplate>
            <EditRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
            <AlternatingRowStyle BackColor="White" />
        </asp:DetailsView>
        <asp:SqlDataSource ID="sdsSuppliersDetails" runat="server" 
            ConnectionString="<%$ ConnectionStrings:KonturConnectionString %>" 
            DeleteCommand="DELETE FROM [Suppliers] WHERE [SupplierID] = @SupplierID" 
            InsertCommand="INSERT INTO [Suppliers] ([Name], [AddressCorrespondence], [AddressInvoice], [IDNUM], [VATNO], [MRP], [Phone], [Fax], [Website], [Bank], [BankAddress], [AccountNo], [BIC], [IBAN], [BankGiro], [PostGiro], [CountryID]) VALUES (@Name, @AddressCorrespondence, @AddressInvoice, @IDNUM, @VATNO, @MRP, @Phone, @Fax, @Website, @Bank, @BankAddress, @AccountNo, @BIC, @IBAN, @BankGiro, @PostGiro, @CountryID )" 
            SelectCommand="SELECT Suppliers.SupplierID, Suppliers.Name, Suppliers.AddressCorrespondence, Suppliers.AddressInvoice, Suppliers.IDNUM, Suppliers.VATNO, Suppliers.MRP, Suppliers.Phone, Suppliers.Fax, Suppliers.Website, Suppliers.Bank, Suppliers.BankAddress, Suppliers.AccountNo, Suppliers.BIC, Suppliers.IBAN, Suppliers.BankGiro, Suppliers.PostGiro, Countries.NameBG FROM Suppliers INNER JOIN Countries ON Suppliers.CountryID = Countries.CountryID WHERE (Suppliers.SupplierID = @SupplierID)" 
            UpdateCommand="UPDATE [Suppliers] SET [Name] = @Name, [AddressCorrespondence] = @AddressCorrespondence, [AddressInvoice] = @AddressInvoice, [IDNUM] = @IDNUM, [VATNO] = @VATNO, [MRP] = @MRP, [Phone] = @Phone, [Fax] = @Fax, [Website] = @Website, [Bank] = @Bank, [BankAddress] = @BankAddress, [AccountNo] = @AccountNo, [BIC] = @BIC, [IBAN] = @IBAN, [BankGiro] = @BankGiro, [PostGiro] = @PostGiro, [CountryID] = @CountryID WHERE [SupplierID] = @SupplierID">
            <SelectParameters>
                <asp:ControlParameter ControlID="gvSuppliers" PropertyName="SelectedValue" Name="SupplierID" Type="Int32" />
            </SelectParameters>
            <DeleteParameters>
                <asp:Parameter Name="SupplierID" Type="Int32" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="Name" Type="String" />
                <asp:Parameter Name="AddressCorrespondence" Type="String" />
                <asp:Parameter Name="AddressInvoice" Type="String" />
                <asp:Parameter Name="IDNUM" Type="String" />
                <asp:Parameter Name="VATNO" Type="String" />
                <asp:Parameter Name="MRP" Type="String" />
                <asp:Parameter Name="Phone" Type="String" />
                <asp:Parameter Name="Fax" Type="String" />
                <asp:Parameter Name="Website" Type="String" />
                <asp:Parameter Name="Bank" Type="String" />
                <asp:Parameter Name="BankAddress" Type="String" />
                <asp:Parameter Name="AccountNo" Type="String" />
                <asp:Parameter Name="BIC" Type="String" />
                <asp:Parameter Name="IBAN" Type="String" />
                <asp:Parameter Name="BankGiro" Type="String" />
                <asp:Parameter Name="PostGiro" Type="String" />
                <asp:ControlParameter Name="CountryID" Type="Int32" ControlID="ctl00$ContentPlaceHolder1$dvSuppliers$ddlCountries" PropertyName="SelectedValue" />
                <asp:Parameter Name="SupplierID" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="Name" Type="String" />
                <asp:Parameter Name="AddressCorrespondence" Type="String" />
                <asp:Parameter Name="AddressInvoice" Type="String" />
                <asp:Parameter Name="IDNUM" Type="String" />
                <asp:Parameter Name="VATNO" Type="String" />
                <asp:Parameter Name="MRP" Type="String" />
                <asp:Parameter Name="Phone" Type="String" />
                <asp:Parameter Name="Fax" Type="String" />
                <asp:Parameter Name="Website" Type="String" />
                <asp:Parameter Name="Bank" Type="String" />
                <asp:Parameter Name="BankAddress" Type="String" />
                <asp:Parameter Name="AccountNo" Type="String" />
                <asp:Parameter Name="BIC" Type="String" />
                <asp:Parameter Name="IBAN" Type="String" />
                <asp:Parameter Name="BankGiro" Type="String" />
                <asp:Parameter Name="PostGiro" Type="String" />
                <asp:ControlParameter Name="CountryID" Type="Int32" ControlID="ctl00$ContentPlaceHolder1$dvSuppliers$ddlCountriesIns" PropertyName="SelectedValue" />
            </InsertParameters>
        </asp:SqlDataSource>
          <asp:SqlDataSource ID="sdsCountries" runat="server" 
            ConnectionString="<%$ ConnectionStrings:KonturConnectionString %>" 
            
            SelectCommand="SELECT [CountryID], [NameBG] FROM [Countries] ORDER BY NameBG">
        </asp:SqlDataSource>
    <br />
    </asp:Content>

